﻿using System;


namespace CoreEx.Common.Mediator
{
    /// <summary>
    /// Represents a mediator that is capable of publishing messages to a list of subscribers.
    /// </summary>
    public interface IMediator
    {  
        /// <summary>
        /// Publishes a new message to all subscribers.
        /// </summary>
        /// <typeparam name="T">The <see cref="Type"/> of parameter to be passed along with the message.</typeparam>
        /// <param name="message">The message to publish</param>
        /// <param name="value">The parameter to be passed along with the <paramref name="message"/>.</param>
        void Publish<T>(string message, T value);
        
        /// <summary>
        /// Subscribes to a message. 
        /// </summary>
        /// <typeparam name="T">The <see cref="Type"/> of parameter sent by the publisher.</typeparam>
        /// <param name="message">The message to subscribe to.</param>
        /// <param name="callback">The delegate that will be invoked when messages are received.</param>
        void Subscribe<T>(string message, Action<T> callback);        
    }
}
